package com.maycur.ctrip.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maycur.ctrip.domain.FeeData;
import com.maycur.ctrip.domain.FeeDynamicField;
import com.maycur.ctrip.enumeration.FeeDynamicFieldCode;
import com.maycur.ctrip.enumeration.FeeSourceType;
import com.maycur.ctrip.enumeration.FeeTypeGroupTag;
import com.maycur.ctrip.util.Constant;
import org.joda.time.DateTime;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by JoeyXin on 6/30/16.
 * 火车票车票信息
 */
public class TrainTicketInfo {

    //车次Id
    @JsonProperty(value = "TrainID")
    private Integer trainId;

    //车次名称
    @JsonProperty(value = "TrainName")
    private String trainName;

    //火车票id
    @JsonProperty(value = "TicketID")
    private Integer ticketId;

    @JsonProperty(value = "DepartureCityName")
    private String departureCityName;

    @JsonProperty(value = "DepartureDateTime")
    private Date departureAt;

    @JsonProperty(value = "DepartureStationName")
    private String departureStationName;

    @JsonProperty(value = "DepartureStationEn")
    private String departureStationNameEN;

    @JsonProperty(value = "ArrivalCityName")
    private String arrivalCityName;

    @JsonProperty(value = "ArrivalStationName")
    private String arrivalStationName;

    @JsonProperty(value = "ArrivalStationEn")
    private String arrivalStationNameEN;

    @JsonProperty(value = "ArrivalDateTime")
    private Date arrivalAt;

    //到达站类型
    @JsonProperty(value = "ArriveStopType")
    private Integer arrivalStationType;

    //首选坐席类型Id
    @JsonProperty(value = "FirstSeatTypeID")
    private Integer firstSeatTypeID;

    //首选坐席类型
    @JsonProperty(value = "FirstSeatTypeName")
    private String  firstSeatTypeName;

    //车票票面价(TicketPrice 是支付时的价格, DealTicketPrice 是实际出票的价格,有可能会存在票价差。)
    @JsonProperty(value = "TicketPrice")
    private BigDecimal ticketAmount;

    //火车类型id
    @JsonProperty(value = "TrainTypeID")
    private Integer trainTypeId;

    //12306 电子订单号
    @JsonProperty(value = "ElectronicOrderNo")
    private String orderIdIn12306;

    @JsonProperty(value = "ServiceFee")
    private BigDecimal serviceAmount;

    //定制类型
    @JsonProperty(value = "CustomType")
    private Integer customType;

    //具体定制内容
    @JsonProperty(value = "CustomDetail")
    private String customDetail;

    //配送费
    @JsonProperty(value = "DeliverFee")
    private BigDecimal postAmount;

    //纸质票出票费
    @JsonProperty(value = "PaperTicketFee")
    private BigDecimal paperTicketAmount;

    public Integer getTrainId() {
        return trainId;
    }

    public void setTrainId(Integer trainId) {
        this.trainId = trainId;
    }

    public String getTrainName() {
        return trainName;
    }

    public void setTrainName(String trainName) {
        this.trainName = trainName;
    }

    public Integer getTicketId() {
        return ticketId;
    }

    public void setTicketId(Integer ticketId) {
        this.ticketId = ticketId;
    }

    public String getDepartureCityName() {
        return departureCityName;
    }

    public void setDepartureCityName(String departureCityName) {
        this.departureCityName = departureCityName;
    }

    public Date getDepartureAt() {
        return departureAt;
    }

    public void setDepartureAt(Date departureAt) {
        this.departureAt = departureAt;
    }

    public String getDepartureStationName() {
        return departureStationName;
    }

    public void setDepartureStationName(String departureStationName) {
        this.departureStationName = departureStationName;
    }

    public String getDepartureStationNameEN() {
        return departureStationNameEN;
    }

    public void setDepartureStationNameEN(String departureStationNameEN) {
        this.departureStationNameEN = departureStationNameEN;
    }

    public String getArrivalCityName() {
        return arrivalCityName;
    }

    public void setArrivalCityName(String arrivalCityName) {
        this.arrivalCityName = arrivalCityName;
    }

    public String getArrivalStationName() {
        return arrivalStationName;
    }

    public void setArrivalStationName(String arrivalStationName) {
        this.arrivalStationName = arrivalStationName;
    }

    public String getArrivalStationNameEN() {
        return arrivalStationNameEN;
    }

    public void setArrivalStationNameEN(String arrivalStationNameEN) {
        this.arrivalStationNameEN = arrivalStationNameEN;
    }

    public Date getArrivalAt() {
        return arrivalAt;
    }

    public void setArrivalAt(Date arrivalAt) {
        this.arrivalAt = arrivalAt;
    }

    public Integer getArrivalStationType() {
        return arrivalStationType;
    }

    public void setArrivalStationType(Integer arrivalStationType) {
        this.arrivalStationType = arrivalStationType;
    }

    public Integer getFirstSeatTypeID() {
        return firstSeatTypeID;
    }

    public void setFirstSeatTypeID(Integer firstSeatTypeID) {
        this.firstSeatTypeID = firstSeatTypeID;
    }

    public String getFirstSeatTypeName() {
        return firstSeatTypeName;
    }

    public void setFirstSeatTypeName(String firstSeatTypeName) {
        this.firstSeatTypeName = firstSeatTypeName;
    }

    public BigDecimal getTicketAmount() {
        return ticketAmount;
    }

    public void setTicketAmount(BigDecimal ticketAmount) {
        this.ticketAmount = ticketAmount;
    }

    public Integer getTrainTypeId() {
        return trainTypeId;
    }

    public void setTrainTypeId(Integer trainTypeId) {
        this.trainTypeId = trainTypeId;
    }

    public String getOrderIdIn12306() {
        return orderIdIn12306;
    }

    public void setOrderIdIn12306(String orderIdIn12306) {
        this.orderIdIn12306 = orderIdIn12306;
    }

    public BigDecimal getServiceAmount() {
        return serviceAmount;
    }

    public void setServiceAmount(BigDecimal serviceAmount) {
        this.serviceAmount = serviceAmount;
    }

    public Integer getCustomType() {
        return customType;
    }

    public void setCustomType(Integer customType) {
        this.customType = customType;
    }

    public String getCustomDetail() {
        return customDetail;
    }

    public void setCustomDetail(String customDetail) {
        this.customDetail = customDetail;
    }

    public BigDecimal getPostAmount() {
        return postAmount;
    }

    public void setPostAmount(BigDecimal postAmount) {
        this.postAmount = postAmount;
    }

    public BigDecimal getPaperTicketAmount() {
        return paperTicketAmount;
    }

    public void setPaperTicketAmount(BigDecimal paperTicketAmount) {
        this.paperTicketAmount = paperTicketAmount;
    }

    public FeeData extractFee(String entCode, String feeCode, String userCode, String passengerName){
        FeeData feeData = new FeeData();

        feeData.setEntCode(entCode);
        feeData.setFeeCode(feeCode);
        feeData.setUserCode(userCode);
        feeData.setComments("乘车人:" + passengerName);

        //默认设置费用类型为员工住宿类型
        feeData.setFeeTypeCode(Constant.DEFAULT_TRAIN_FEE_TYPE);

        //消费金额
        //支付方式1 现金, 2 信用卡 ,3 支付宝, 4 借记卡, 5 其他
        //feeData.setPayMethod(PayType.fromDesc(payType));
        feeData.setConsumeAmount(ticketAmount.add(serviceAmount));
        feeData.setConsumeCcy(Constant.DEFAULT_CTRIP_CURRENCY);
        //feeData.setConsumeTime(orderedAt);
        //feeData.setSourceId(orderId);
        feeData.setSourceType(FeeSourceType.CTRIP.getCode());
        feeData.setStatus(Constant.DEFAULT_FEE_STATUS);
        feeData.setFeeTypeGroupTags(FeeTypeGroupTag.Train);

        feeData.setBaseCcy(Constant.DEFAULT_CTRIP_CURRENCY);
        feeData.setExchangeRate(Constant.DEFAULT_EXCHANGE_RATE);
        feeData.setSysExchangeRate(Constant.DEFAULT_EXCHANGE_RATE);
        feeData.setFeeAmount(feeData.getConsumeAmount());
        feeData.setApprovedAmount(feeData.getConsumeAmount());

        feeData.setValid(true);
        return feeData;
    }

    public List<FeeDynamicField> extractFeeDynamicFields(String entCode, String feeCode) {
        List<FeeDynamicField> feeDynamicFields = new ArrayList<>();

        for(FeeDynamicFieldCode dynamicFieldCode:FeeDynamicFieldCode.getTrainFieldCodes()){
            FeeDynamicField dynamicField = new FeeDynamicField();
            dynamicField.setEntCode(entCode);
            dynamicField.setFeeCode(feeCode);
            dynamicField.setFeeTypeCode(Constant.DEFAULT_TRAIN_FEE_TYPE);
            dynamicField.setFeeKind(Constant.DEFAULT_FEE_KIND);
            dynamicField.setFeeDetailChooseCode(dynamicFieldCode.getCode());

            switch(dynamicFieldCode) {
                case TRAIN_CONSUMPTION_PLATFORM:
                    dynamicField.setFeeDetailChooseValue(Constant.DEFAULT_CONSUMPTION_PLATFORM);
                    break;
                case TRAIN_DEPARTURE_CITY:
                    dynamicField.setFeeDetailChooseValue(departureCityName);
                    break;
                case TRAIN_ARRIVAL_CITY:
                    dynamicField.setFeeDetailChooseValue(arrivalCityName);
                    break;
                case TRAIN_DEPARTURE_TIME:
                    dynamicField.setFeeDetailChooseValue(new DateTime(departureAt).toString(Constant.DATE_TIME_FORMAT));
                    break;
                case TRAIN_ARRIVAL_TIME:
                    dynamicField.setFeeDetailChooseValue(new DateTime(arrivalAt).toString(Constant.DATE_TIME_FORMAT));
                    break;
                case TRAIN_CLASS_NAME:
                    dynamicField.setFeeDetailChooseValue(firstSeatTypeName);
                    break;
            }

            feeDynamicFields.add(dynamicField);
        }

        return feeDynamicFields;
    }

}
